<?php
function SVC_FUNC_GET($request)
{
    if(($dbconn=worker::get_dbconn('DB1')) == false)
        return false;

    if(!isset($request['loginname']) ||
            strlen($request['loginname']) > misc::NAME_SIZE)
    {
        $response=array('errcode'=>SOAR_ERR::PARA);
        return $response;
    }
    $loginname=$request['loginname'];

//    try
//    {
//        $stmt=$dbconn->prepare("select uuid,".
//                "date_format(create_ts,'%Y%m%d%H%i%s'),".
//                "date_format(update_ts,'%Y%m%d%H%i%s'),".
//                "loginname,nickname,login_times ".
//                "from memb_info where loginname=:loginname");
//        $stmt->execute(array(':loginname'=>$loginname));
//        $row=$stmt->fetch(PDO::FETCH_NUM);
//        //print_r($row);
//        if(empty($row))
//        {
//            $response=array('errcode'=>'MEMB_NOT_FOUND');
//        }
//        else
//        {
//            $response=array('errcode'=>SOAR_ERR::OK);
//            $paras['uuid']=>$row[0];
//            $paras['create_ts']=>$row[1];
//            $paras['update_ts']=>$row[2];
//            $paras['loginname']=>$row[3];
//            $paras['nickname']=>$row[4];
//            $paras['login_times']=>$row[5];
//            $response['paras']=$paras;
//        }
//    }
//    catch(PDOException $e)
//    {
//        errlog::add("%s: worker(%d) select memb_info fail: %s",
//                __METHOD__, worker::$worker_idx,
//                $e->getMessage()); 
//        return false;
//    }

    $stmt=$dbconn->prepare(
            "select uuid,".
            "date_format(create_ts,'%Y%m%d%H%i%s'),".
            "date_format(update_ts,'%Y%m%d%H%i%s'),".
            "loginname,nickname,login_times ".
            "from memb_info where loginname=?"
            );
    if($stmt === false)
    {
        errlog::add("%s: worker(%d) prepare fail:%d %s",
                __METHOD__, worker::$worker_idx,
                 $dbconn->errno, $dbconn->error);
        return false;
    }
    $stmt->bind_param('s', $loginname);
    if($stmt->execute() == false)
    {
        errlog::add("%s: worker(%d) mysqli_query fail:%d %s",
                __METHOD__, worker::$worker_idx,
                 $stmt->errno, $stmt->error);
        return false;
    }
    $stmt->store_result();
    if($stmt->num_rows() == 0)
    {
        $response=array('errcode'=>'MEMB_NOT_FOUND');
    }
    else
    {
        $stmt->bind_result($uuid, $create_ts, $update_ts,
                $loginname, $nickname, $login_times);
        $stmt->fetch();
        $response=array('errcode'=>SOAR_ERR::OK);
        $paras['uuid']=$uuid;
        $paras['create_ts']=$create_ts;
        $paras['update_ts']=$update_ts;
        $paras['loginname']=$loginname;
        $paras['nickname']=$nickname;
        $paras['login_times']=$login_times;
        $response['paras']=$paras;
    }
    $stmt->close();

    return $response;
}
?>
